#!/usr/bin/env python
import sys

def main():
    back = forward = []
    url = 'http://www.acm.org/'
    n = int(sys.stdin.readline())
    for line in sys.stdin:
        msg = 'Ignored'
        line = line.strip('\n')
        if line == 'QUIT':
            back = forward = []
            url = 'http://www.acm.org/'
            continue
        l = line.split(' ')
#visit url
        if len(l) == 2:
            back.append(url)
            url = l[1];
            msg = url
            forward = []
        else:
#get command
            cmd = l[0]
            if cmd == 'BACK':
                if back != []:
                    forward.append(url)
                    url = back.pop()
                    msg = url
            elif cmd == 'FORWARD':
                if forward != []:
                    back.append(url)
                    url = forward.pop()
                    msg = url
        print msg
if __name__ == '__main__':
    main()
